<!DOCTYPE html>
<html>
<head>
	<title>calc load time</title>
	<script type="text/javascript">
		var when_ready = (function(){
			var funcs = [];
			var ready = false;
			function handler(e){
				//console.log("now at : " + e.type)
				//若已经运行过直接返回
				//if(ready) return;
				//若文档尚未准备好
				if(e.type === "readystatechange" && document.readyState !== "complete") return;
				for(var i = 0;i<funcs.length;i++)
					funcs[i].call(document,e);
				ready = true;
				//funcs = null;
			}
			if(document.addEventListener){
				document.addEventListener("DOMContentLoaded",handler,false);
				document.addEventListener("readystatechange",handler,false);
				window.addEventListener("load",handler,false);
			}
			else if(document.attachEvent){
				document.attachEvent("onreadystatechange",handler);
				window.attachEvent("onload",handler);
			}
			return function whenReady(f){
				if(ready) f.call(document);
				else funcs.push(f);
			}
		}());

		when_ready(function(event){
			console.log("event : " + event.type);
			var d = new Date();
			console.log(d.toString());
			console.log("( " + Date.parse(d) + " )");
		})
	</script>
</head>
<body>
<h1>Calc Load Time</h1>
</body>
</html>